﻿
#ifndef _SIMPLE_EVENT_H_
#define _SIMPLE_EVENT_H_

#if defined(WIN32)
#include <windows.h>
#else
#include <pthread.h>
#endif

#include <stdint.h>

namespace base {

class  SimpleEvent
{
public:
	// 默认为自动重置锁
	SimpleEvent(bool bManualReset = false);

	~SimpleEvent();

public:
	void Set();

	void Reset();

	void Wait();

	bool TryWait(uint32_t msec/*millisecond*/ = 0);

private:
#if defined(WIN32)
	HANDLE				m_handle;
#endif
#if defined(LINUX) || defined(ANDROID) || defined(IOS)
	pthread_cond_t		m_handle;			// 条件变量
	volatile bool		m_flag;				// 信标
	pthread_mutex_t		m_mutex;			// 锁
#endif
	bool				m_bManualReset;		// 是否手工重置
};

} // namespace base

#endif//_SIMPLE_EVENT_H_
